//
//  SelectContactTableViewCell.m
//  OAProject
//
//  Created by yhj on 2017/3/10.
//  Copyright © 2017年 cdnunion. All rights reserved.
//

#import "SelectContactTableViewCell.h"

@interface SelectContactTableViewCell ()

// 头像
@property(nonatomic,strong)UIImageView *headURL;

// 名字
@property(nonatomic,strong)UILabel *nameLabel;

@property(nonatomic,strong)UIButton *isSelectBtn;

@end

@implementation SelectContactTableViewCell

-(void)setCellModel:(SelectContactTableViewCellModel *)cellModel
{
    _cellModel=cellModel;

    self.nameLabel.text=cellModel.contactName;

    // 判断是否选中
    if (cellModel.isChoose)
    {
        [self.isSelectBtn setImage:[UIImage imageNamed:@"selected"] forState:0];
    }
    else
    {
        [self.isSelectBtn setImage:[UIImage imageNamed:@"no_select"] forState:0];
    }

}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        // ➡️Cell类型
        self.accessoryType=UITableViewCellAccessoryNone;

        self.headURL.image=[UIImage imageNamed:@"contact_head"];

       [self.isSelectBtn setImage:[UIImage imageNamed:@"no_select"] forState:0];

        self.headURL.hidden=NO;

        self.nameLabel.font=Font_Number(13);

        self.backgroundColor=WhiteColor;

    }
    return self;
}

-(void)isSelectBtnEvent:(UIButton *)sender
{
    if (self.delegate&&[self.delegate respondsToSelector:@selector(cell:isSelectContactTableViewCellModel:headSectionModel:)])
    {
        [self.delegate cell:self isSelectContactTableViewCellModel:self.cellModel headSectionModel:self.sectionModel];
    }
}

// isSelectBtn
-(UIButton *)isSelectBtn
{
    if (!_isSelectBtn) {
        _isSelectBtn=[UIButton new];
        [self addSubview:_isSelectBtn];
        [_isSelectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(kmargin*3/2,kmargin*3/2));
            make.centerY.mas_equalTo(self);
            make.left.mas_equalTo(kmargin*8);
        }];
        [_isSelectBtn addTarget:self action:@selector(isSelectBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _isSelectBtn;
}


// headURL
-(UIImageView *)headURL
{
    if (!_headURL) {
        _headURL=[[UIImageView alloc]init];
        [self.contentView addSubview:_headURL];
        // 圆角和边框
        ViewBorderRadius(_headURL,kmargin*3/2,kmargin/kmargin,ClearColor);

        [_headURL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.isSelectBtn.mas_right).offset(kmargin);
            make.centerY.mas_equalTo(self);
            make.size.mas_equalTo(CGSizeMake(kmargin*3,kmargin*3));
        }];
    }
    return _headURL;
}

// nameLabel
- (UILabel *)nameLabel
{

    if (!_nameLabel) {
        _nameLabel=[self getLabelWithText:@"黄伟海" font:Font_Number(13) textColor:Color999999 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.contentView addSubview:_nameLabel];
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.headURL.mas_right).offset(kmargin);
            make.centerY.mas_equalTo(self);
            make.width.mas_equalTo(APPW/4);
        }];
    }
    return _nameLabel;
}

@end
